package mysql

import (
	"errors"
	"gorm.io/gorm"
)

type Good struct {
	gorm.Model
	Name  string  `gorm:"type: varchar(100);not null;comment:'景区名字'" json:"name"`
	Num   int64   `gorm:"type: int;not null;comment:'门票数量'" json:"num"`
	Dates string  `gorm:"type: varchar(100);not null;comment:'门票日期'" json:"dates"`
	Price float64 `gorm:"type:decimal(10,2);not null;comment:'价格'" json:"price"`
}

func (g *Good) Find(name string) error {
	goods := Good{}
	err := DB.Where("name =?", name).Find(&goods).Error
	if err != nil {
		return err
	}
	return errors.New("有此商品")
}

func (g *Good) Updated(num int64) error {
	err := DB.Where("num =?", num).Update("num", g.Num-num).Error
	if err != nil {
		return errors.New("更改库存不成功")
	}
	return errors.New("更改成功")
}
